home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 49
/
Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso
/
-in_the_mag-
/
program_perfection
/
test.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-12-08
|
2KB
|
80 lines
/*
* test.c
*
* A quick and dirty test for text class
*
* Pass <filename> as an argument to dump file to console.
*
* $Id :$
* $Log:$
*
*/
#include "defs.h"
#include "lines.h"
#include "text.h"
#include "memory.h"
#include "errors.h"
#include <dos/dos.h>
#include <proto/dos.h>
int
main( int argc, char **argv )
{
ERROR_TYPE err = NULL;
if( argc > 1 )
{
BPTR file;
/* open file */
if( file = Open( argv[1], MODE_OLDFILE ) )
{
LONG file_length;
APTR file_buf;
/* find file size */
Seek( file, 0L, OFFSET_END );
file_length = Seek( file, 0L, OFFSET_BEGINNING );
Printf( "size: %ld\n", file_length );
/* allocate buffer */
if( file_buf = ( Memory_Alloc( file_length ) ) )
{
if( Read( file, file_buf, file_length ) == file_length )
{
/* dump it to the console */
TEXT_PTR t;
LINE_PTR l;
t = Text_New( file_buf, &err );
FPrintf( Output(), "Longest line:%ld\n\n", Text_GetMaxWidth( t ) );
/* walk this list */
for( l = Text_GetTopLine( t ); l; l = Text_GetNextLine( t, l ) )
{
Line_FPuts( Output(), l );
}
}
/* done with buffer */
Memory_Free( file_buf, file_length );
}
/* done with file */
Close( file );
}
else
MyExit( "Couldn't open file '%s'", argv[1] );
}
MyExit( NULL );
}